cmake_minimum_required(VERSION 3.0.2)
project(show_img)

add_compile_options(-std=c++11)
add_compile_options(-w)  # 抑制警告信息

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  std_msgs
)

find_package(OpenCV REQUIRED)

# 声明catkin包
catkin_package(
  CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
)

# 包含目录
include_directories(
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)

# 生成可执行文件
add_executable(show_img src/show_img.cpp)

# 依赖项
add_dependencies(show_img ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

# 链接库（添加跨平台系统库）
target_link_libraries(show_img
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

# 针对不同系统链接额外库
if(UNIX AND NOT APPLE)  # Linux
  target_link_libraries(show_img X11)
elseif(APPLE)  # macOS
  find_library(COCOA_LIBRARY Cocoa)
  target_link_libraries(show_img ${COCOA_LIBRARY})
elif(WIN32)  # 补充Windows支持
  target_link_libraries(show_img user32)
endif()

# 安装可执行文件
install(TARGETS show_img
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

# 安装launch目录（新增）
install(DIRECTORY launch/
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
)

# 安装config目录（新增）
install(DIRECTORY config/
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
)
